package main.java.DMDE.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Class Attribute
 */
public class Attribute {

	private Type type;
	private String name;
	private Visibility visibility;
	private List<Modifier> modifiers = null;

	public Attribute(String name, Type type) {
		this.type = type;
		this.name = name;
		this.setModifiers(new ArrayList<Modifier>());
	};

	public Attribute() {
		this.setModifiers(new ArrayList<Modifier>());
	}

	/**
	 * Set the value of type
	 * 
	 * @param newVar
	 *            the new value of type
	 */
	public void setType(Type newVar) {
		type = newVar;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Get the value of type
	 * 
	 * @return the value of type
	 */
	public Type getType() {
		return type;
	}

	public String getName() {
		return name;
	}

	public boolean is(Attribute attribute) {
		return attribute.getName().equals(this.name);
	}

	public Visibility getVisibility() {
		return visibility;
	}

	public void setVisibility(Visibility visibility) {
		this.visibility = visibility;
	}

	public List<Modifier> getModifiers() {
		return modifiers;
	}

	public void setModifiers(List<Modifier> modifiers) {
		this.modifiers = modifiers;
	}

	/**
	 * Returns true if already exists a modifier with the same name
	 */
	private boolean containsModifier(Modifier modifier) {
		for (Modifier modif : modifiers) {
			if (modif.is(modifier))
				return true;
		}
		return false;
	}

	public void addModifier(Modifier modifier) {
		if (!containsModifier(modifier))
			modifiers.add(modifier);
	}
	
	public String toString(){
	    return this.getName() + ":" + this.getType().getName();
	}

}
